﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Mogre.Tests
{
  public partial class OgreUserControl : UserControl
  {
    private IOgreControl _ogreControl;
    private bool _running = false;

    public OgreUserControl(IOgreControl ogreControl)
    {
      _ogreControl = ogreControl;
      InitializeComponent();
      Size = new Size(800, 600);
      Disposed += OgreForm_Disposed;
      Resize += OgreForm_Resize;
    }

    public void StartRendering()
    {
      _running = true;
      Show();
      while (_ogreControl.RunOneFrame())
        Application.DoEvents();
    }

    private void OgreForm_Resize(object sender, EventArgs e)
    {
      if (_running)
        _ogreControl.OgreForm_Resize(sender, e);
    }

    private void OgreForm_Disposed(object sender, EventArgs e)
    {
      if (_running)
        _ogreControl.OgreForm_Disposed(sender, e);
    }

    public void Init()
    {
      _ogreControl.Init(this.Handle);
    }
  }
}
